package com.edgclub.edg.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.edgclub.edg.R;
import com.edgclub.edg.activity.UserInfoOtherActivity;
import com.edgclub.edg.model.User;
import com.edgclub.edg.utils.GlideUtil.GlideUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 好友适配器
 * 
 * @author 陈坤彬
 * 
 */
public class GroupMenberAdapter extends BaseAdapter {

	private Context mContext;
	private List<User> list;
	private GlideUtils glideUtils;

	public GroupMenberAdapter(Context context) {
		this.mContext = context;
		glideUtils=new GlideUtils();
	}
	public void setList(final List<User> list1) {
		((Activity) mContext).runOnUiThread(new Runnable() {
            public void run() {
            	list = list1;
            	if (null ==list) {
            		list=new ArrayList<User>();
        		}
                 notifyDataSetChanged();
            }
		});
	}



	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public int getCount() {
		if(list.size()>5){
			return 5;
		}else{
			return list.size();
		}
//			return 5;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup arg2) {
		ViewHolder holder = null;
		final User lists = list.get(position);
		if (null == convertView) {
		convertView = LayoutInflater.from(mContext).inflate(
				R.layout.item_group_plepeo_icon, null);
		holder = new ViewHolder();
		holder.image = (ImageView) convertView.findViewById(R.id.image);
		holder.vip = (ImageView) convertView.findViewById(R.id.vip);
		convertView.setTag(R.id.tag_first,holder);
		}else {
			holder = (ViewHolder) convertView.getTag(R.id.tag_first);
		}

		glideUtils.Glidde_loadCropCircleImage(mContext,lists.getLogo(),holder.image);
		holder.image.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				Intent intent=new Intent(mContext, UserInfoOtherActivity.class);
				intent.putExtra("user",lists);
				mContext.startActivity(intent);
			}
		});
		if(null!=lists.getUserAuth()){

			if ("-1".equals(lists.getUserAuth().getType())){
				holder.vip.setVisibility(View.GONE);
			}
			if("0".equals(lists.getUserAuth().getType())){
				holder.vip.setVisibility(View.VISIBLE);
				holder.vip.setImageResource(R.drawable.v_huan);
			}else if("1".equals(lists.getUserAuth().getType())){
				holder.vip.setVisibility(View.VISIBLE);
				holder.vip.setImageResource(R.drawable.v_lan);
			}
		}else{
			holder.vip.setVisibility(View.GONE);
		}
		
		return convertView;
	}
	class ViewHolder {
	    private ImageView image , vip;
	}
}
